n = int(input())
lst1 = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]

lst_m = [1,0,'X',9,8,7,6,5,4,3,2]

res = []
for _ in range(n):
    str1 = input()
    str1 += ""
    sum1 = 0
    flag = False
    for item in range(17):
        if str1[item] == 'X':
            res.append(str1)
            flag = True
            break
        else:
#             print(int(str1[item]),end = "*")
#             print(lst1[int(str1[item])])
            sum1 += int(str1[item]) * lst1[item]
    sum1 = sum1 % 11
    if str1[-1] != str(lst_m[sum1]) and flag == False:
        res.append(str1)
if len(res) == 0:
    print("All passed")
else:
    for i in range(len(res)):
        print(res[i])